public class PeriodicTable {
  Button[][] hashtable;
  PImage img;
  ArrayList<Button> elements;
  boolean selected;
  float picscalex;
  float picscaley;
  ElementLoader e;

  public PeriodicTable() {
    img = loadImage("ptable.png");
    picscalex = (1.0 * screenWidth)/img.width;
    picscaley = (1.0 * screenHeight)/img.height;
    img.resize(screenWidth, screenHeight);
    background(img);
    e = new ElementLoader();
    elements = e.load(picscalex, picscaley);
  }

  public void mouseAct(float x, float y) {
    if (!selected) {
      for (Button b : elements) {
        if (b.isClicked(x, y)) {
          img = loadImage(b.data+".png");
          float tmpscalex;
          float tmpscaley;
          tmpscalex = (1.0 * screenWidth)/img.width;
          tmpscaley = (1.0 * screenHeight)/img.height;
          img.resize(screenWidth, screenHeight);
          background(img);
          fill(255);
          noStroke();
          rect(tmpscalex*380,tmpscaley*38,tmpscalex*137,tmpscaley*21);
          selected = true;
        }
      }
    }
  }

  public void keyboardAct() {
    if (key == CODED && keyCode == KeyEvent.KEYCODE_BACK) {
      img = loadImage("ptable.png");
      img.resize(screenWidth, screenHeight);
      background(img);
      selected = false;
      keyCode = 1;
      if (waszoomed) {
        zoomed = true;
        waszoomed = false;
      }
    }
  }

}

